
//
//  RSCalculator.m
//  RSTools
//
//  Created by thinkjoy on 2017/10/20.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "RSCalculator.h"

@interface RSCalculator()

@end

@implementation RSCalculator

- (instancetype)init
{
    self    =   [super init];
    if (self) {
        self.result =   0;
    }
    return self;
}
-(RSCalculator *(^)(NSInteger num))add
{
    return ^id(NSInteger num) {
        self.result += num;
        return self;
    };
}

-(RSCalculator *(^)(NSInteger))subtract
{
    return ^id(NSInteger num){
        self.result -= num;
        return self;
    };
}

-(RSCalculator *(^)(NSInteger))multiply
{
    return ^id(NSInteger num){
        self.result *=num;
        return self;
    };
}

-(RSCalculator *(^)(NSInteger))divide{
    return ^id (NSInteger num){
        NSAssert(num!=0, @"被除数不能为0");
        self.result /= num;
        return self;
    };
}

@end
